{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "[1, 12, -5, -6]\n",
      "5\n",
      "[12, -5, -6, 50]\n",
      "6\n",
      "[-5, -6, 50, 3]\n"
     ]
    }
   ],
   "source": [
    "nums = [1,12,-5,-6,50,3]\n",
    "\n",
    "k = 4\n",
    "i = 0\n",
    "\n",
    "while i+k <= len(nums):\n",
    "    print(i+k)\n",
    "    print(nums[i:i+k])\n",
    "    i += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.75"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from math import inf\n",
    "\n",
    "nums = [1,12,-5,-6,50,3]\n",
    "\n",
    "k = 4\n",
    "i = 0\n",
    "\n",
    "maxV = -inf\n",
    "while i+k <= len(nums):\n",
    "    s = sum(nums[i:i+k])\n",
    "    if s > maxV:\n",
    "        maxV = s\n",
    "    i += 1\n",
    "\n",
    "maxV/k"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/maximum-average-subarray-i\n",
    "\n",
    "\n",
    "Time Limit Exceeded\n",
    "\n",
    "\n",
    "```python\n",
    "from math import inf\n",
    "\n",
    "class Solution:\n",
    "    def findMaxAverage(self, nums: List[int], k: int) -> float:\n",
    "        i = 0\n",
    "\n",
    "        maxV = -inf\n",
    "        while i+k <= len(nums):\n",
    "            s = sum(nums[i:i+k])\n",
    "            if s > maxV:\n",
    "                maxV = s\n",
    "            i += 1\n",
    "\n",
    "        return maxV/k\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
